package org.idea.spring.look.up.exception;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;

import javax.annotation.PostConstruct;

/**
 * @Author linhao
 * @Date created in 10:01 下午 2021/4/12
 */
public class BeanCreationExceptionDemo {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext annotationConfigApplicationContext  = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.register(POJO.class);
        DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) annotationConfigApplicationContext.getBeanFactory();
        defaultListableBeanFactory.getBean("");
        annotationConfigApplicationContext.refresh();
        annotationConfigApplicationContext.close();
    }



    static class POJO implements InitializingBean {

        //这里的基于注解的回调是通过 CommonAnnotationBeanPostProcessor 来实现的
        @PostConstruct
        public void init(){
            throw  new RuntimeException(" init has error");
        }

        @Override
        public void afterPropertiesSet() throws Exception {
            throw  new RuntimeException(" afterPropertiesSet : has error");
        }
    }
}
